#include "stdafx.h"
#include "UiElement.h"
#include "..\..\..\..\EdgeGraphics\HUD.h"
#include "..\..\..\..\EdgeGraphics\Texture2D.h"

/*virtual*/ UiElement::~UiElement(void)
{
	if (texture)
		delete texture;
}

/*virtual*/ void UiElement::Update(float dt) /*override*/
{
	// update events
	Vector2 mouse_location = Input::GetInstance()->getMousePosition();
	if (clientRect.Contains(mouse_location))
	{
		// raise the mouse hover event
		void* params[1] = { this };
		OnMouseHover(params);
		if (Input::GetInstance()->isKeyPressed(MouseButtons::Left))
		{
			// raise the clicked event
			OnClicked(params);
		}
	}
}

/*virtual*/ void UiElement::Draw(void) /*override*/
{
	if (texture)
		Hud::GetInstance()->DrawRectangle((int)clientRect.left, (int)clientRect.top, (int)clientRect.getWidth(), (int)clientRect.getHeight(), texture);
}